package cn.edu.szpt.qqdemov3.d517;

import static com.android.volley.Request.Method.GET;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.File;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import cn.edu.szpt.qqdemov3.R;
import cn.edu.szpt.qqdemov3.beans.QQContactBean;

public class VolleyTestActivity extends AppCompatActivity {


    ArrayList<TeamBean> data;
    private String url;


    public static final String SERVER = "http://8.129.167.217";
    public static final String GETJSON_URL = SERVER + "/SoccerDataHandler.ashx?action=getTeamWithFlagList";
    QQTeamAdapter teamAdapte;

    public static final String GETFLAG_URL = SERVER + "/images/";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_volley_test);

//        File photos = getExternalFilesDir("photos");
//        photos.get


        RecyclerView recyclerView = findViewById(R.id.recyclerView);

        recyclerView.setLayoutManager(new LinearLayoutManager(this.getApplication()));

//        recyclerView.set
            data = new ArrayList<>();

        data.add(new TeamBean("1", "1", "1", "1", "1"));
        teamAdapte = new QQTeamAdapter(this, data,voll);

        recyclerView.setAdapter(teamAdapte);

        RequestQueue queue = Volley.newRequestQueue(this.getApplication());
        Log.d("TAG", "onCreate: "+GETJSON_URL);

        StringRequest stringRequest = new StringRequest(GETJSON_URL, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                Type type = new TypeToken<List<TeamBean>>() {
                }.getType();

                data = gson.fromJson(response, type);

                teamAdapte.setData(data);
                teamAdapte.notifyDataSetChanged();

                Log.d("TAG", "onResponse: " + response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {


            }
        });

        queue.add(stringRequest);

    }
}